package com.iflytek.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iflytek.dao.ProjectDao;
import com.iflytek.domain.Hometype;
import com.iflytek.domain.MenuType;
import com.iflytek.domain.PageBean;
import com.iflytek.domain.Project;
import com.iflytek.domain.ProjectType;
import com.iflytek.service.ProjectService;

@Service
public class ProjectServiceImpl implements ProjectService {
	
	@Autowired
	private ProjectDao pd;

	@Override
	public List<Project> getAllProject() {
		return pd.getAllProject();
	}

	@Override
	public PageBean getPageProjectByPid(String pid,int currentPage,int currentCount,String pt_id) {
		if(pt_id.equals("1")) {
			int totalCount=0;
			totalCount=pd.getProjectCountByPid(pid);
			int totalPage=(int)Math.ceil(1.0*totalCount/currentCount);
			PageBean <Hometype> pageBean =new PageBean<Hometype>();
			pageBean.setCurrentPage(currentPage);
			pageBean.setCurrentCount(currentCount);
			pageBean.setTotalCount(totalCount);
			pageBean.setTotalPage(totalPage);
			int index=(currentPage-1)*currentCount;
			List<Hometype> list =pd.getHometypePageBeanByCid(pid,index,currentCount);
			pageBean.setList(list);
			return pageBean;
		}
		if(pt_id.equals("2")) {
			int totalCount=0;
			totalCount=pd.getProjectCountByPid(pid);
			int totalPage=(int)Math.ceil(1.0*totalCount/currentCount);
			PageBean <MenuType> pageBean =new PageBean<MenuType>();
			pageBean.setCurrentPage(currentPage);
			pageBean.setCurrentCount(currentCount);
			pageBean.setTotalCount(totalCount);
			pageBean.setTotalPage(totalPage);
			int index=(currentPage-1)*currentCount;
			List<MenuType> list =pd.getMenutypePageBeanByCid(pid,index,currentCount);
			pageBean.setList(list);
			return pageBean;
		}
		return null;
	}

	@Override
	public Hometype getHometypeById(String htid) {
		return  pd.getHometypeByHtid(htid);
	}

	@Override
	public ProjectType getProjectTypeByProjectId(String pid) {
		return	pd.getProjectTypeByProjectId(pid);
	}

	@Override
	public List<String> getAutoSearchWord(String search) {
		return  pd.getAutoSearchWord(search);
	}

	@Override
	public Project getProjectByPid(String projectId) {
		return pd.getProjectByPid(projectId);
	}

}
